package com.atguigu.serviceBase.exception;

import com.atguigu.commonUtils.ExceptionUtil;
import com.atguigu.commonUtils.Result;
import com.atguigu.commonUtils.ResultEnum;
import com.atguigu.commonUtils.ResultUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result<Exception> exceptionHandler(Exception e){
        e.printStackTrace();
        log.error(ExceptionUtil.getMessage(e));
        return ResultUtil.fail(ResultEnum.INTERNAL_SERVER_ERROR.message, e.getMessage());
    }

}
